<?php
namespace backend\models;
use common\component\BaseActiveRecord;
use common\utils\CommonUtil;
use yii\db\ActiveRecord;
use Yii;


/**
 * This is the model class for table "zt_admin".
 *
 * @property integer $id
 * @property string $username
 *  * @property string $password
 */
class User extends \yii\db\ActiveRecord
{

    public $username;
    public $password;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'zt_admin';
    }

    public function afterFind()
    {
        parent::afterFind();

        $this->attrUi();
    }
    public function attrUi() {
        $this->ui["username"] = $this->username;
        $this->ui["password"] = $this->password;
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['username'], 'string', 'max' => 32],
            ['password','required'],
            ['password','string','min' => 3],
            [['username'],'filter','filter'=>function ($value) {
                if (empty($value)) {
                    return Yii::$app->params["prefix_name"].CommonUtil::buildRandomNumber(6);
                }
                return $value;
            }]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'username' => '用户名',
            'password' => '密码',
        ];
    }
    /**
     * 实例化模型对像
     * @param $id
     * @return BaseActiveRecord|null|\common\models\User
     */
    public static function modelById($id) {
        if (!$id) {
            $model = new self();
        }
        else {
            $model = static::findOne($id);
        }
        return $model;
    }

   public function checkUser($params){
            if(empty($params['account'])||empty($params['checkPass'])){
                return 0;
            }
       $sql = "select From `zt_login`";
       $connection = Yii::$app->db->createCommand()->queryAll() ;
   }
}